package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.DbBean;
import bean.weiboBean;

/**
 * Servlet implementation class publishsvl
 */
@WebServlet("/publishsvl")
public class publishsvl extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public publishsvl() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		weiboBean pb = new weiboBean();
		HttpSession session = request.getSession();	
		DbBean db = new DbBean();		
		request.setCharacterEncoding("utf-8");
		String textarea = request.getParameter("text");		
		int id = (int)session.getAttribute("userId");
		//System.out.print(id);
		if(pb.publish(textarea, id)){
			request.getRequestDispatcher("indexsvl").forward(request, response);
		}else{
			response.sendRedirect("publish.jsp");
		}
		
	}
	}


